package com.eqdd.yiqidian.utils;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.GlideCircleTransformCenterCrop;
import com.eqdd.yiqidian.adapter.GlideRoundTransformCenterCrop;
import com.eqdd.yiqidian.base.BaseApplication;
import com.eqdd.yiqidian.base.GlideApp;

/**
 * Created by vzhihao on 2016/7/29.
 */
public class ImageUtil {
    public static RequestOptions optionsNormal;
    public static RequestOptions optionsRound;
    public static RequestOptions optionsCircle;
    static {
        optionsCircle = new RequestOptions()
                .placeholder(R.mipmap.ic_launcher_logo)
                .error(R.mipmap.ic_launcher_logo)
                .transform(new GlideCircleTransformCenterCrop());
    }
    static {
        optionsNormal = new RequestOptions()
                .centerCrop()
                .placeholder(R.mipmap.ic_launcher_logo)
                .error(R.mipmap.ic_launcher_logo);
    }
    static {
        optionsRound = new RequestOptions()
                .placeholder(R.mipmap.ic_launcher_logo)
                .error(R.mipmap.ic_launcher_logo)
                .transform(new GlideRoundTransformCenterCrop(20));
    }
    public static void setCircleImage(RequestManager requestManager, Object url, ImageView imageView) {
        requestManager.load(url).apply(optionsCircle).into(imageView);
    }
    public static void setImage(RequestManager requestManager,Object url, ImageView imageView) {
        requestManager.load(url).apply(optionsNormal).into(imageView);
    }
    public static void setCircleImage(Object url, ImageView imageView) {
        GlideApp.with(BaseApplication.getApplication()).load(url).apply(optionsCircle).into(imageView);
    }

    public static void setCircleImage(int url, ImageView imageView) {
        GlideApp.with(BaseApplication.getApplication()).load(url).apply(optionsCircle).into(imageView);
    }

    public static void setImage(Object url, ImageView imageView) {
        GlideApp.with(BaseApplication.getApplication()).asBitmap().load(url).apply(optionsNormal).into(imageView);
    }

    public static void setRoundImage(Object url, ImageView imageView) {
        GlideApp.with(BaseApplication.getApplication()).load(url).apply(optionsRound).into(imageView);
    }

}
